<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" :label-col="labelCol" :wrapper-col="wrapperCol" labelAlign="left" :form="form">
          <a-row :gutter="48">

            <template v-if="!advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="操作模块 ">
                  <a-input  placeholder="" v-model="search" />
                </a-form-item>
              </a-col>
            </template>

<!--            <template v-if="advanced">-->
<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="补丁编号:">-->
<!--                  <a-input placeholder="请输入" v-decorator="['patchNo']"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="补丁描述:">-->
<!--                  <a-input placeholder="" v-decorator="['abs']"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="危险等级:">-->
<!--                  <a-select  placeholder="请选择" v-decorator="['dangerLv']">-->
<!--                    <a-select-option value="">全部</a-select-option>-->
<!--                    <a-select-option v-for="item in DangerLevel" :value="item.value">{{item.label}}</a-select-option>-->
<!--                  </a-select>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="操作系统:">-->
<!--                  <a-select  placeholder="请选择" v-decorator="['adaptationOs']">-->
<!--                    <a-select-option value="">全部</a-select-option>-->
<!--                    <a-select-option v-for="item in Ostype" :value="item.value">{{item.label}}</a-select-option>-->
<!--                  </a-select>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="补丁类型:">-->
<!--                  <a-select  placeholder="请选择" v-decorator="['patchTypes']">-->
<!--                    <a-select-option value="">全部</a-select-option>-->
<!--                    <a-select-option v-for="item in PatchType" :value="item.value">{{item.label}}</a-select-option>-->
<!--                  </a-select>-->
<!--                </a-form-item>-->
<!--              </a-col>-->


<!--              <a-col :md="8" :sm="24">-->
<!--                <a-form-item label="发布时间:">-->
<!--                  <a-date-picker  v-decorator="['publishingTime']" style="width: 100%;"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--            </template>-->
            <a-col :md="(!advanced && 8) || 24" :sm="24">
                    <span
                      class="table-page-search-submitButtons"
                      :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
                    >
                      <a-button type="primary" @click="searchlog()">查询</a-button>
<!--                      <a-button style="margin-left: 8px" @click="resetform()">重置</a-button>-->

<!--                      <a @click="toggleAdvanced" style="margin-left: 8px">-->
<!--                        {{ advanced ? '收起' : '展开' }}-->
<!--                        <a-icon :type="advanced ? 'up' : 'down'" />-->
<!--                      </a>-->
                    </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-row>
        <a-table :columns="columns" :data-source="data"  :pagination="tablepagination"  @change="tablechange">
          <template slot="cz" slot-scope="text, record">
            <a-button type="link" @click="showdetail(record)">详情</a-button>
          </template>
        </a-table>
      </a-row>
    </a-card>
    <Detailmodal ref="detailmodal"></Detailmodal>
  </page-header-wrapper>
</template>

<script>
  import { getPolicylist,getPolicyLog } from '@/api/log'
  import Detailmodal from '@/components/mycomp/detailmodal'
  import moment from 'moment'
  import { getpackinfo } from '@/api/assets'
  import Mymodal from '@/components/mycomp/mymodal'
  export default {
    name: 'policy',
    components: { Detailmodal },
    data(){
      return{
        search:'',
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 },
        },
        advanced:false,
        tablepagination:{
          showTotal:(total, range) => {return `共搜索到${total}条数据`},
          current:1,
          total:0
        },
        form:this.$form.createForm(this, { name: 'plog' }),
        columns:[
          {
            title: '策略名称',
            dataIndex: 'strategy_name',
            key: 'strategy_name',
            width: 100
          },
          {
            title: '执行时间',
            dataIndex: 'time',
            key: 'time',
            width: 100
          },
          {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width:100,
            scopedSlots: { customRender: 'cz' },
          },
        ],
        data:[],
      }
    },
    mounted() {
      this.getlist()
    },
    methods:{
      getlist(){
        let params = {}
        params.operModul = '策略管理'
        params.pageNo = this.tablepagination.current-1
        params.pageSize = 10
        params.search = this.search
        getPolicyLog(params).then(res=>{
          let record = res.data.records
          for(let i in record){
            record[i].key = record[i].id
            record[i].time = moment(new Date(record[i].timestamp*1000)).format('YYYY-MM-DD HH:mm:ss')
          }
          this.data = record
          this.tablepagination.total = res.data.total
        })
      },
      tablechange(pagination){
        this.tablepagination = pagination
        this.getlist()
      },
      toggleAdvanced() {
        this.advanced = !this.advanced
      },
      searchlog(){
        this.tablepagination.current = 1
        this.getlist()
      },
      showdetail(record){
        let data = []
        for(let i in record.result){
          let j = {}
          j.name =  record.result[i].name
          j.counts_fail =  record.result[i].result.counts_fail
          j.counts_success =  record.result[i].result.counts_success
          j.counts_unreachable =  record.result[i].result.counts_unreachable
          j.failed =  record.result[i].result.failed
          j.unreachable =  record.result[i].result.unreachable
          data.push(j)
        }

        let modalinfo = {
          title:'日志详情',
          type:'table',
          width:1000,
          nopage:true,
          data:data,
          list:[
            {label:'软件包名称',value:'name'},
            {label:'执行失败资产数',value:'counts_fail'},
            {label:'执行成功资产数',value:'counts_success'},
            {label:'不可达资产数',value:'counts_unreachable'},
            {label:'失败详情',value:'failed'},
            {label:'不可达详情',value:'unreachable'},
          ],
        }
        this.$refs.detailmodal.showmodal(modalinfo)
      }
    }
  }
</script>

<style scoped>

</style>